package com.example.bbgds.test;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.RelativeLayout;

/**
 * Created by bbgds on 2016/3/7.
 */
public class Layout2 extends RelativeLayout{

    private Button mButton;
    private View mContentView;
    private long duration = 400;

    public Layout2(Context context) {
        super(context);
    }

    public Layout2(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Layout2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onFinishInflate(){
        super.onFinishInflate();
        mContentView = findViewById(R.id.content);
        mButton = (Button)findViewById(R.id.goButton);
        mButton.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                mButton.animate().alpha(0.5f).translationY(-200).setDuration(duration).start();
                start();
            }
        });
    }

    private void start(){
        mContentView.setVisibility(View.VISIBLE);
        ObjectAnimator translation = ObjectAnimator.ofFloat(mContentView, "translationY", 400, 0);
        translation.setDuration(duration);
        translation.setInterpolator(new AccelerateInterpolator());
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(mContentView, "scaleX", 0, 1f);
        scaleX.setInterpolator(new AccelerateInterpolator());
        scaleX.setDuration(duration);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(mContentView, "scaleY", 0, 1f);
        scaleX.setInterpolator(new AccelerateInterpolator());
        scaleY.setDuration(duration);
        AnimatorSet s1 = new AnimatorSet();
        s1.playTogether(translation, scaleX, scaleY);
        s1.start();
    }
}
